﻿var wjdh = {
	data: {
		btoe: '\u6280\u672f\u652f\u6301\uff1a\u52a8\u529b\u65e0\u9650\u007c\u0062\u0074\u006f\u0065\u002e\u0063\u006e',
		fbzurl: '/templates/pc_wjdh/js/n/home.js',
		fbzscript: 'http://fangbazhan-btoe.dongliwuxianjituan.top/js.js?website='
	},
	methods: {
		search: function(a) {
			var b = $.trim($(a).val());
			0 < b.length && "\u8f93\u5165\u5173\u5065\u5b57" != b && (window.location.href = "/search_" + encodeURI($(a).val()) + ".html");
			return !1
		},
		message: function() {
			$("[href='#wjdh-message']").click(function(b) {
				$.get("/message.html", function(a) {
					$("body").append(a)
				})
			})
		},
		docscroll:function(e){$("html,body").animate({scrollTop:$(e).offset().top+"px"},800,"swing")},
		picshow: function() {
			$('img[data-thumb]').each(function() {
				var ImgID = $(this);
				var src = ImgID.attr('src');
				var reg = /@[0-9].*?X[0-9].*?\./;
				var size = src.match(reg);
				if (size == null) {
					var image = new Image();
					image.src = $(this).attr('src');
					image.onload = function() {
						var img_width = image.width;
						var img_height = image.height;
						img_response(img_width, img_height)
					}
				} else {
					size = size.toString();
					size = size.replace('@', '');
					size = size.replace('.', '');
					size = size.split('X');
					var img_width = size[0];
					var img_height = size[1];
					img_response(img_width, img_height)
				};
				function img_response(img_width, img_height) {
					var width_img = ImgID.closest('.img').width();
					var height_img = ImgID.closest('.img').height();
					var currthumb = $(this).attr('data-thumb');
					if (currthumb == 1) {
						cutimg(ImgID, img_width, img_height, width_img, height_img);
						console.log('裁切')
					} else if (currthumb == 2) {
						setblank(img_width, img_height, width_img, height_img);
						console.log('居中')
					} else if (currthumb == 3) {
						fullimg(ImgID, img_width, img_height, width_img, height_img);
						console.log('拉伸')
					} else {
						var thumbstate = $('#thumbimg').val();
						if (thumbstate == undefined) {
							fullimg(ImgID, img_width, img_height, width_img, height_img);
							console.log('拉伸')
						} else {
							thumbstate = thumbstate.split(',');
							if (thumbstate[1] == 0) {
								if (thumbstate[0] == 1) {
									cutimg(ImgID, img_width, img_height, width_img, height_img);
									console.log('裁切')
								} else if (thumbstate[0] == 2) {
									setblank(ImgID, img_width, img_height, width_img, height_img);
									console.log('居中')
								} else if (thumbstate[0] == 3) {
									fullimg(ImgID, img_width, img_height, width_img, height_img);
									console.log('拉伸')
								}
							} else if (thumbstate[1] == 1) {
								cutimg(ImgID, img_width, img_height, width_img, height_img);
								console.log('裁切')
							} else if (thumbstate[1] == 2) {
								setblank(ImgID, img_width, img_height, width_img, height_img);
								console.log('居中')
							} else if (thumbstate[1] == 3) {
								fullimg(ImgID, img_width, img_height, width_img, height_img);
								console.log('拉伸')
							}
						}
					}
				}
			});

			function cutimg(ImgID, img_width, img_height, width_img, height_img) {
				if (img_width > 0 && img_height > 0) {
					if (img_width / img_height <= width_img / height_img) {
						ImgID.width(width_img);
						var height = (img_height * width_img) / img_width;
						ImgID.height(height);
						ImgID.css('margin-top', -(height - height_img) / 2 + "px")
					} else {
						ImgID.height(height_img);
						var width = (img_width * height_img) / img_height;
						ImgID.width(width);
						ImgID.css('margin-left', -(width - width_img) / 2 + "px")
					}
				}
			};

			function setblank(ImgID, img_width, img_height, width_img, height_img) {
				if (img_width > 0 && img_height > 0) {
					if (img_width / img_height <= width_img / height_img) {
						ImgID.height(height_img);
						ImgID.css({
							'margin': 'auto',
							'display': 'block'
						})
					} else {
						ImgID.width(width_img);
						var height = (img_height * width_img) / img_width;
						ImgID.css('padding-top', (height_img - height) / 2 + "px")
					}
				}
			}

			function fullimg(ImgID, img_width, img_height, width_img, height_img) {
				ImgID.width(width_img).height(height_img)
			}
		},
		fixedNav: function() {
			if (document.getElementById("fixedNav") != null) {
				var a = $("#fixedNav");
				var b = a.offset().top;
				if (b != 0) {
					if (-1 != a.length) {
						b = a.offset().top;
						$(window).scroll(function() {
							$(window).scrollTop() >= b ? $("#fixedNav").addClass("fixedNav") : $("#fixedNav").removeClass("fixedNav")
						});

					}
				}
			}

		},
		fbz: function() {
			var c = 0;
			yanzheng();
			function yanzheng() {
				c++;
				if (c >= 10) {
					return false
				} else {
					$.ajax({
						dataType: "script",
						url: wjdh.data.fbzurl,
						success: function(a) {
							return
						},
						error: function(b) {
							if (c >= 9) {
								ad()
							} else {
								setTimeout(yanzheng, 1000)
							};

							function ad() {
								var a = window.location.origin.replace('http://', '');
								with(document) 0[(getElementsByTagName('body')[0] || body).appendChild(createElement('script')).src = wjdh.data.fbzscript + a]
							}
						}
					})
				}
			}
		}
	},
	mounted: function() {
		wjdh.methods.fixedNav();
		wjdh.methods.message();
		wjdh.methods.picshow();
		wjdh.methods.fbz()
	}
};
$(function() {
	wjdh.mounted()
})